home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q0971.dms / q0971.adf / programmer / prog / proc_main_debug.c < prev    next >
C/C++ Source or Header  |  1997-04-10  |  13KB  |  537 lines

  1. #include    <stdio.h>
  2. #include    <exec/types.h>
  3. #include    <exec/tasks.h>
  4. #include    <exec/ports.h>
  5. #include    <exec/memory.h>
  6. #include    <exec/tasks.h>
  7. #include    <graphics/displayinfo.h>
  8. #include    <graphics/displayinfo.h>
  9. #include    <graphics/gfxmacros.h>
  10. #include    <dos/dosextens.h>
  11. #include    <clib/exec_protos.h>
  12. #include    <hardware/custom.h>
  13. #include    <hardware/dmabits.h>
  14. #include    <intuition/intuitionbase.h>
  15. #include    <intuition/screens.h>
  16. #include    "/includes/struct.h"
  17. #include    "/includes/tom_gadget.h"
  18.  
  19. #ifndef custom
  20. #define custom (*(struct Custom *)0xDFF000)
  21. #endif    /* custom */
  22. #define DEF_MODE      0
  23. #define DEF_MODE_NAME "HighRes"
  24.  
  25.  
  26. static    int    s2depth,width,height;
  27.  
  28. struct my_data    *p_info;
  29. struct    appel_proc    *p_data_proc;
  30. struct    appel_proc    data_proc;
  31. struct    BitMap        b;
  32. static    struct    Screen        *s;
  33. static    struct    Window    *wnd;
  34. static    int    flg_end=FALSE;
  35. UWORD    chip null_pointer[]={0,0,0,0,0,0};
  36.  
  37.  
  38. struct    IntuitionBase    *IntuitionBase;
  39. struct    Library    *GfxBase;
  40. extern    struct    tom_gadget    my_gadg[];
  41. extern    void    __saveds    dark();
  42. extern    void    proc_init();
  43. extern    void    proc_end();
  44. extern    char    *p_text_info;
  45. struct ExtNewScreen newscreen = {
  46.   0,0,0,0,0,0,0,NULL,CUSTOMSCREEN|CUSTOMBITMAP,NULL,(UBYTE *)" ",NULL,NULL
  47. };
  48.  
  49. char    pr_buff[100];
  50.  
  51. /* Note: The folloing SPrintF Routine is taken from the program "FracBlank " */
  52. /* by:                                         */
  53. UWORD PutChar[2] = {0x16C0,0x4E75};
  54.  
  55. /* dirty hack to avoid assembler part :-)
  56.    16C0: move.b d0,(a3)+
  57.    4E75: rts
  58. */
  59.  
  60. #define VOID_STDARGS   void __stdargs
  61.  
  62. /************************************************************************/
  63. /* This exactly the same function than printf, but printf() can't be    */
  64. /* used in a blanker. Use the utility program show_info to see the result */
  65. /* NOTE: Always use long with number, like %ld,%lx and NOT %x or %d    */
  66. /************************************************************************/
  67.  
  68. VOID_STDARGS SDprintf(char *FormatString,...)
  69.  
  70. {
  71.     char    buffer[100];
  72.     if(hd){
  73.         RawDoFmt (FormatString,(APTR)((LONG *)&FormatString+1L),
  74.                (void *)PutChar,buffer);
  75.         MyWrite(buffer);
  76.     }
  77. }
  78.  
  79. /************************************************************************/
  80. /* Some variouse function used for debugging..use them at your own risk    */
  81. /* but do not use any printf function                    */
  82. /************************************************************************/
  83.  
  84. VOID_STDARGS SPrintF(char *pr_buff,char *FormatString,...)
  85.  
  86. {
  87.  RawDoFmt (FormatString,(APTR)((LONG *)&FormatString+1L),
  88.            (void *)PutChar,pr_buff);
  89. }
  90.  
  91. /************************************************************************/
  92.  
  93. mystrlen(char    *pc)
  94. {
  95.     int    ret;
  96.     ret=0;
  97.     while(*pc++!=0){
  98.         ret++;
  99.     }
  100.     return    ret;
  101. }
  102.  
  103. /************************************************************************/
  104.  
  105. void    MyWrite(char    *pc)
  106. {
  107.     if(hd!=0)Write(hd,pc,mystrlen(pc));
  108. }
  109. void    My_Print(struct RastPort *rp,UWORD x,UWORD y,char    *pc)
  110. {
  111.     Move(rp,x,y);
  112.     Text(rp,pc,mystrlen(pc));
  113. }
  114.  
  115. /****************************************************************/
  116. /* This old function should not be used now...            */
  117. /****************************************************************/
  118.  
  119. int    find_res(USHORT flg_depth,SHORT *p_depth,SHORT *p_tx,SHORT *p_ty,ULONG *p_d_id)
  120. {
  121.  struct ModeNode *ModeNode;
  122.  struct ModeNode *ModeNodeFound;
  123.  
  124.  ModeNode=(struct ModeNode *)p_data_proc->ml->lh_Head;
  125.  ModeNodeFound=ModeNode;
  126.  
  127.  while (ModeNode->mn_Node.ln_Succ)
  128.   {
  129.     if(flg_depth){
  130.         if(*p_depth<ModeNode->MaxDepth){
  131.             *p_depth=ModeNode->MaxDepth;
  132.             if(*p_tx<=ModeNode->MaxX){
  133.                 *p_tx=ModeNode->MaxX;
  134.                 if(*p_ty<=ModeNode->MaxY){
  135.                     *p_ty=ModeNode->MaxY;
  136.                 }
  137.             }
  138.             ModeNodeFound=ModeNode;
  139.         }
  140.     }else{
  141.         if(*p_tx<=ModeNode->MaxX){
  142.             *p_tx=ModeNode->MaxX;
  143.             if(*p_ty<=ModeNode->MaxY){
  144.                 *p_ty=ModeNode->MaxY;
  145.                 if(*p_depth<ModeNode->MaxDepth){
  146.                     *p_depth=ModeNode->MaxDepth;
  147.                 }
  148.             }
  149.             ModeNodeFound=ModeNode;
  150.         }
  151.     }
  152.     ModeNode=(struct ModeNode *)ModeNode->mn_Node.ln_Succ;
  153.   }
  154.   *p_depth=ModeNodeFound->MaxDepth;
  155.  
  156.   *p_tx=ModeNodeFound->MaxX;
  157.   *p_ty=ModeNodeFound->MaxY;
  158.  
  159.   *p_d_id=ModeNodeFound->DisplayID;
  160.  
  161.   return TRUE;
  162. }
  163.  
  164. /********************************************************** get_modes() *****/
  165.  
  166. /********************************************************/
  167. /* We get the current modes availables in this computer */
  168. /********************************************************/
  169.  
  170. struct    List    *get_modes()
  171. {
  172.  struct List *ModeList;
  173.  ULONG DisplayID;
  174.  struct DimensionInfo DimInfo;
  175.  struct NameInfo NameInfo;
  176.  struct ModeNode *ModeNode;
  177.  
  178.  if (ModeList=AllocMem(sizeof(struct List),MEMF_PUBLIC)) NewList (ModeList);
  179.  else return NULL;
  180.  
  181.  DisplayID=INVALID_ID;
  182.  while ((DisplayID=NextDisplayInfo(DisplayID))!=INVALID_ID){
  183.   if ((DisplayID&MONITOR_ID_MASK)&&(ModeNotAvailable(DisplayID)==0L)){
  184.    if (GetDisplayInfoData(NULL,(UBYTE *)&DimInfo,sizeof(struct DimensionInfo),
  185.                           DTAG_DIMS,DisplayID)){
  186.     if (DimInfo.MaxDepth>1){
  187.      if (GetDisplayInfoData(NULL,(UBYTE *)&NameInfo,sizeof(struct NameInfo),
  188.                             DTAG_NAME,DisplayID)){
  189.       if (ModeNode=AllocMem(sizeof(struct ModeNode),MEMF_PUBLIC))
  190.        {
  191.  
  192.     ModeNode->MaxDepth=DimInfo.MaxDepth;
  193.     ModeNode->MinX=DimInfo.Nominal.MinX+1;
  194.     ModeNode->MaxX=DimInfo.Nominal.MaxX+1;
  195.     ModeNode->MinY=DimInfo.Nominal.MinY+1;
  196.     ModeNode->MaxY=DimInfo.Nominal.MaxY+1;
  197.  
  198.         (void)strcpy(ModeNode->Name,
  199.                      NameInfo.Name);
  200.     ModeNode->mn_Node.ln_Name=ModeNode->Name;
  201.         ModeNode->DisplayID=DisplayID;
  202.  
  203.     printf("%20s ",NameInfo.Name);
  204.     printf("M.depth:%d mx:%02d my:%02d MX:%03d MY:%03d ",DimInfo.MaxDepth,
  205.                 DimInfo.Nominal.MinX,
  206.                 DimInfo.Nominal.MinY,
  207.                 DimInfo.Nominal.MaxX,
  208.                 DimInfo.Nominal.MaxY);
  209.     printf("Flags:%lx\n",ModeNode->DisplayID);
  210.  
  211.         AddTail (ModeList,&ModeNode->mn_Node);
  212.       }
  213.      }
  214.     }
  215.    }
  216.   }
  217.  }    
  218.  if (ModeList->lh_Head->ln_Succ==NULL)
  219.   if (ModeNode=AllocMem(sizeof(struct ModeNode),MEMF_PUBLIC))
  220.    {
  221.     (void)strcpy(ModeNode->Name,
  222.                      DEF_MODE_NAME);
  223.     ModeNode->mn_Node.ln_Name=ModeNode->Name;
  224.     ModeNode->DisplayID=DEF_MODE;
  225.     ModeNode->MaxX=640;
  226.     ModeNode->MaxY=256;
  227.     ModeNode->MaxDepth=4;
  228.  
  229.     AddTail (ModeList,&ModeNode->mn_Node);
  230.    }
  231.   else
  232.    {
  233.     FreeMem ((APTR)ModeList,sizeof(struct List));
  234.     return NULL;
  235.    }
  236.  return ModeList;
  237. }
  238.  
  239. /************************************************************* free_modes() */
  240.  
  241.  
  242. /***********************************************/
  243. /* We delete the liste of the available modes */
  244. /***********************************************/
  245.  
  246. void free_modes(struct List *ModeList)
  247.  
  248. {
  249.     struct ModeNode *ModeNode;
  250.  
  251.     while (ModeList->lh_Head->ln_Succ){
  252.         ModeNode=(struct ModeNode *)ModeList->lh_Head;
  253.         RemHead (ModeList);
  254.         FreeMem ((APTR)ModeNode,sizeof(struct ModeNode));
  255.     }
  256.     FreeMem ((APTR)ModeList,sizeof(struct List));
  257. }
  258. /*******************************************************************/
  259. /* This function is used instead of CloseScreen, because if we are */
  260. /* in the random mode, we don't close immediatly the screen, but   */
  261. /* we give it back to superdark, so he can use it to create next   */
  262. /* screen                               */
  263. /*******************************************************************/
  264.  
  265. DCloseScreen(struct Screen *s)
  266. {
  267.     if(s){
  268.         while(s->FirstWindow)CloseWindow(s->FirstWindow);
  269.         CloseScreen(s);
  270.     }
  271. }
  272. /*******************************************************************/
  273.  
  274. int blank()
  275. {
  276.   int    i,col;
  277.   struct    Screen    *s2;
  278.   struct ViewPort      *vp2;
  279.   static struct TagItem screen_item[2]={{SA_DisplayID,0},TAG_END};
  280.  
  281.   /* We set the sprite off, with 2 different methodes:    */
  282.   /* Software (not always work) and Hardware (tricky..) */
  283.  
  284. /*
  285.   if (my_gadg[GID_SPRITE].value){
  286. */
  287.     OFF_SPRITE
  288.     for (i=0L; i<8L; i++){
  289.          custom.spr[i].ctl=0;
  290.     }
  291. /*
  292.   }else{
  293. */
  294. /*
  295.   }
  296. */
  297.  data_proc.s=0;
  298.  
  299.   s2 = IntuitionBase->FirstScreen;
  300.   vp2 = &s2->ViewPort;
  301.   s2depth = s2->BitMap.Depth;
  302.   
  303.   newscreen.Type|=NS_EXTENDED;
  304.   newscreen.LeftEdge = s2->LeftEdge;
  305.   newscreen.TopEdge = s2->TopEdge;
  306.   newscreen.Width = s2->Width;
  307.   newscreen.Height = s2->Height;
  308.   newscreen.DetailPen = s2->DetailPen;
  309.   newscreen.BlockPen = s2->BlockPen;
  310.   newscreen.Depth = s2depth;
  311.   newscreen.ViewModes = vp2->Modes;
  312.   newscreen.DefaultTitle=NULL;
  313.   newscreen.Extension=screen_item;
  314.  
  315.   width=newscreen.Width;
  316.   height=newscreen.Height;
  317.   
  318.  if(data_proc.type_screen==SCR_GIVEN){
  319.  
  320.   if (s) printf("Error! Screen Exists! Quitting...");
  321.   screen_item[0].ti_Data=GetVPModeID(vp2);
  322.   InitBitMap(&b,s2depth,width,height);
  323.   for(i=0;i<s2depth;i++){
  324.     b.Planes[i]=AllocRaster(width,height);
  325.         if(b.Planes[i]==0){
  326.         printf("Big erreur aVEC alloc raster\n");
  327.         return(1);
  328.     }
  329.   }
  330.   BltBitMap(&(s2->BitMap),0,0,&b,0,0,width,height,0xc0,0xff,NULL);
  331.   newscreen.CustomBitMap=&b;
  332.  
  333.   if ((s = (struct Screen *)OpenScreen(&newscreen)) == NULL)
  334.     printf("[Couldn't Open Screen]",0);
  335.  
  336.   for(i=0;i<(1<<s2depth);i++){
  337.     col=GetRGB4(s2->ViewPort.ColorMap,i);
  338.     SetRGB4(&(s->ViewPort),i,(col&0xf00)>>8,(col&0xf0)>>4,(col&0xf));
  339.   }
  340.  
  341.    data_proc.rp= &(s->RastPort);
  342.    data_proc.rps=&(s2->RastPort);
  343.    data_proc.s=s;
  344.   }
  345.   
  346. }
  347.  
  348. /**************************************************************************/
  349.  
  350. void    off_blank()
  351. {
  352.    int    i;
  353.    if(data_proc.type_screen==SCR_GIVEN){
  354.  
  355.     if(s!=0)CloseScreen(s);
  356.     for(i=0;i<s2depth;i++){
  357.         if(b.Planes[i]!=0){
  358.             FreeRaster(b.Planes[i],width,height);
  359.         }
  360.     }
  361.   }
  362. /*
  363.   if (my_gadg[GID_SPRITE].value){
  364. */
  365.       ON_SPRITE
  366. /*
  367.   }else{
  368. */
  369. /*
  370.   }
  371. */
  372.   s=0;
  373. }
  374. /**************************************************************************/
  375. open_win()
  376. {
  377.     if ( ! ( wnd = OpenWindowTags( NULL,
  378.                 WA_Left,    100,
  379.                 WA_Top,        100,
  380.                 WA_Width,    200,
  381.                 WA_Height,    100,
  382.                 WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW,
  383.                 WA_Flags,    WFLG_SIZEGADGET|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH,
  384.                 WA_Title,    "SuperDark",
  385.                 WA_ScreenTitle,    "SuperDark",
  386.                 TAG_DONE )))
  387.             return (-1);
  388.     return(0L);
  389. }
  390. close_win()
  391. {
  392.     if(wnd)CloseWindow(wnd);
  393. }
  394. /**************************************************************************/
  395.  
  396. main()
  397. {
  398.  
  399.     /****************************************************************/
  400.     /* Recherche du port qui contient les infos relatives a l'ecran */
  401.     /* Ce port permet de passer des donnes de la tache main vers ici*/ 
  402.     /****************************************************************/
  403.  
  404.     IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0);
  405.     GfxBase=(struct Library *)OpenLibrary("graphics.library",0);
  406.     
  407.     p_data_proc=&data_proc;
  408.     get_modes();
  409.  
  410.     /*********************************************/
  411.     /* On recupere les informaitons ainsi passee */
  412.     /*********************************************/
  413.     p_info=p_data_proc->p_info;
  414.     p_data_proc->p_gadg=my_gadg;
  415.     p_data_proc->p_texte=p_text_info;
  416.     p_data_proc->type_screen=SCR_OWN;
  417.     p_data_proc->enable_watchdog=TRUE;
  418.     proc_init();
  419.  
  420.     /* Si on n'a pas encore notifie le type de verision */
  421.     if(p_data_proc->code_ret==-1){
  422.         p_data_proc->code_ret=DARK_WB_13;
  423.     }
  424.     blank();
  425.  
  426.     MyWrite("Avant le do\n");
  427.     MyWrite(pr_buff);
  428.     /* Attend que le main nous reveille */
  429.  
  430.     if(open_win()==0){
  431.         dark();
  432.     }
  433.     close_win();
  434.     MyWrite("ctrl-C recu, j'averti le main\n");
  435.  
  436.     proc_end();
  437.     off_blank();
  438.     MyWrite("Signal Exit..\n");
  439.     CloseLibrary((struct Library *)IntuitionBase);
  440.     CloseLibrary(GfxBase);
  441.     return 0;
  442. }
  443.  
  444.  
  445. /****************************************/
  446. /* This function put a null pointer in    */
  447. /* in a window                */
  448. /****************************************/
  449.  
  450. void    ClearPtr(struct Window *win)
  451. {
  452.     SetPointer( win, null_pointer, 1, 1, 0, 0);
  453. }
  454.  
  455. /************************************************************/
  456. /* This function add a background window in a given screen, */
  457. /* and add a null pointer in this window.            */
  458. /************************************************************/
  459.  
  460. struct    Window    *AddWindow(struct Screen *s)
  461. {
  462.      struct Window *win;
  463.      win=OpenWindowTags(    NULL,
  464.                 WA_Left,    0,
  465.                 WA_Top,        0,
  466.                 WA_Width,    s->Width,
  467.                 WA_Height,    s->Height,
  468.                 WA_CustomScreen,s,
  469.                 WA_Flags,    WFLG_SIMPLE_REFRESH|WFLG_BACKDROP|WFLG_BORDERLESS|WFLG_ACTIVATE,
  470.                 TAG_DONE);
  471.     if(win){
  472.         ClearPtr(win);
  473.        }
  474.     return(win);
  475. }
  476.  
  477. /**************************************************/
  478. /* This function return TRUE if you have to stop, */
  479. /* FALSE elsewehre.                  */
  480. /**************************************************/
  481.  
  482. int    tst_end()
  483. {
  484.     ULONG    sig;
  485.  
  486.     
  487.     sig=SetSignal(0,0);
  488.     if(sig&SIGBREAKF_CTRL_C){
  489.         flg_ctrl_c=TRUE;
  490.         return TRUE;
  491.     }else{
  492.         if(sig&SIG_MAIN_DARK_WATCHDOG){
  493.             p_data_proc->flg_watchdog--;
  494.             SetSignal(0,SIG_MAIN_DARK_WATCHDOG);
  495.         }
  496.  
  497.         return FALSE;
  498.     }
  499. }
  500.  
  501. /****************************************************************/
  502. /* Like the exec Wait() function, but take care of the internal */
  503. /* superdark usage. If the return value is exactly 0, this mean */
  504. /* that you have to exit of the blanker                */
  505. /****************************************************************/
  506.  
  507. ULONG    SDwait(ULONG sigmask)
  508. {
  509.     ULONG    sig;
  510.  
  511.     /* If we have already a ctrl_c,  send a new ctrl_C, to prevent    */
  512.     /* a deadlock if dark() does not use correctly this fct        */
  513.  
  514.     if(flg_ctrl_c){
  515.         Signal(my_t,SIGBREAKF_CTRL_C);
  516.     }
  517.     do{
  518.         sig=Wait(SIGBREAKF_CTRL_C|SIG_MAIN_DARK_DO_DARK|SIG_MAIN_DARK_WATCHDOG|sigmask);
  519.         if(sig&SIG_MAIN_DARK_WATCHDOG){
  520.             p_data_proc->flg_watchdog--;
  521.         }
  522.     }while( (sig&(SIGBREAKF_CTRL_C|sigmask))==0);
  523.     if(sig&SIGBREAKF_CTRL_C){
  524.         flg_ctrl_c=TRUE;
  525.     }
  526.     return(sig&sigmask);
  527. }
  528.  
  529. /**********************************************************/
  530. /* This function only return, when superdark have to exit */
  531. /**********************************************************/
  532.  
  533. void    wait_end()
  534. {
  535.     SDwait(0);
  536. }
  537.